package com.project.drugs;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class MenuMax {
	int er = 3;
	private final String passwords="123";
	static JPasswordField text;
	
	final ExtendsJFrame me;
	
	public MenuMax() {
		me = new ExtendsJFrame("医药仓库管理系统",600,400);
		me.setLayout(new GridLayout(8,1));
		
		JPanel panel1 = new JPanel();
		JPanel panel2 = new JPanel();
		JPanel panel3 = new JPanel();
		JPanel panel4 = new JPanel();
		JPanel panel5 = new JPanel();
		JPanel panel6 = new JPanel();
		JPanel panel7 = new JPanel();
		JPanel panel8 = new JPanel();
		JLabel JL1 = new JLabel("企业网址：www.zua.edu.cn");
		JLabel JL2 = new JLabel("联系地址：郑州航空工业管理学院");
		JLabel JL3 = new JLabel("邮政编码：450046");
		JLabel JL4 = new JLabel("豫ICP备05002444号");
		panel7.add(JL1);
		panel7.add(JL2);
		panel8.add(JL3);
		panel8.add(JL4);
		JButton ton1 = new JButton("添加药品");
		JButton ton2 = new JButton("开取药品");
		JButton ton3 = new JButton("管理药品");
		JButton ton4 = new JButton("查看库存");
		JLabel JL = new JLabel("医药仓库管理系统");
		JL.setFont(new Font("宋体",Font.BOLD, 20));
		panel1.add(JL);
		panel3.add(ton1);
		panel3.add(new JLabel("               "));
		panel3.add(ton2);
		panel5.add(ton3);
		panel5.add(new JLabel("               "));
		panel5.add(ton4);
		me.add(panel1);
		me.add(panel2);
		me.add(panel3);
		me.add(panel4);
		me.add(panel5);
		me.add(panel6);
		me.add(panel7);
		me.add(panel8);
		me.setVisible(true);
		ton1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				final ExtendsJFrame jf = new ExtendsJFrame("添加药品",400,300);
				jf.setLayout(new GridLayout(1,2));
		        JButton jb1 = new JButton("添加新药品");
		        JButton jb2 = new JButton("添加原有药品");
		        jf.add(jb1);
		        jf.add(jb2);
		        jb1.addActionListener(new ActionListener() {
					
		        	@Override
					public void actionPerformed(ActionEvent e) {
						// TODO Auto-generated method stub
		        		jf.dispose();
						new Menu("添加新药品",null,null);
					}
				});
		        jb2.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						// TODO Auto-generated method stub
						jf.dispose();
						new Menu("添加原有药品","编号","数量");
					}
				});
		        
			}
		});
		ton2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				final ExtendsJFrame jf = new ExtendsJFrame("开取药品",400,300);
				jf.setLayout(new GridLayout(2,1));
		        JButton jb5 = new JButton("按编号开取");
		        JButton jb6 = new JButton("按名称开取");
		        jf.add(jb5);
		        jf.add(jb6);
		        jb5.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						// TODO Auto-generated method stub
						jf.dispose();
						new Menu("按编号开取","编号","数量");
					}
				});
		        jb6.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						// TODO Auto-generated method stub
						jf.dispose();
						new Menu("按名称开取","名称","数量");
					}
				});
			}
		});
		ton3.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				passwords();
			}
		});
		ton4.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				new Menu();
			}
		});
	}
		
	//二级验证

	protected void passwords() {

		final ExtendsJFrame rame = new ExtendsJFrame("二级验证",300,200);
		rame.setLayout(new GridLayout(5,1));
		final JPanel anel1 = new JPanel();
		final JPanel anel = new JPanel();
		final JPanel anel2 = new JPanel();
		final JPanel anel3 = new JPanel();
		JLabel abel = new JLabel("管理员密码");
		text = new JPasswordField(7);
		JButton tton1 = new JButton("确定");
		JButton tton2 = new JButton("取消");
		
		tton1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
				if(text.getText().equals(passwords)) {
					
					JOptionPane.showMessageDialog(null,"验证成功.","提示",1);
					rame.dispose();
					final ExtendsJFrame jf11 = new ExtendsJFrame("管理药品",400,300);
					jf11.setLayout(new GridLayout(1,2));
			        JButton jb3 = new JButton("修改");
			        JButton jb4 = new JButton("删除");
			        jf11.add(jb3);
			        jf11.add(jb4);
			        jb3.addActionListener(new ActionListener() {
						
						@Override
						public void actionPerformed(ActionEvent e) {
							// TODO Auto-generated method stub
							jf11.dispose();
							new Menu("修改药品","编号","名称");
						}
					});
			        
			        jb4.addActionListener(new ActionListener() {
						
						@Override
						public void actionPerformed(ActionEvent e) {
							// TODO Auto-generated method stub
							jf11.dispose();
							new Menu("删除药品","编号","名称");
						}
					});
				}
				else {
					er--;
					if(er==0) {
						JOptionPane.showMessageDialog(null,"程序异常","警告",2);
						System.exit(0);
					}
					JOptionPane.showMessageDialog(null,"密码错误,剩余输入次数"+er+"次","错误 ",0);
					rame.dispose();
					passwords();
				}
				
			}
		});
		tton2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				rame.dispose();
			}
		});
		anel3.add(abel);
		anel3.add(text);
		anel2.add(tton1);
		anel2.add(tton2);
		rame.add(anel1);
		rame.add(anel3);
		rame.add(anel);
		rame.add(anel2);
	}
	public static void main(String[] args) {
		//new Menumax();
	}
}

